from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django_moderation.config import ACTION_CHOICES

class AttributeSet(models.Model):
    name = models.CharField(max_length = 75, unique = True)
    active = models.BooleanField(default = True)
    description = models.TextField()
    
class Attribute(models.Model):
    name = models.CharField(max_length = 75, unique = True)
    active = models.BooleanField(default = True)
    description = models.TextField()
    unique = models.BooleanField(default = False)
    set = models.ForeignKey(AttributeSet)

class ObjectAttribute(models.Model):
    attribute = models.ForeignKey(Attribute)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()
    
    date_created = models.DateTimeField()
    date_modified = models.DateTimeField()
    
class ObjectAttributeVote(models.Model):
    info = models.TextField(default = '')
    attribute = models.ForeignKey(Attribute)
    user = models.ForeignKey(User)
    
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()

class AttributeInducedAction(models.Model):
    name = models.CharField(max_length = 75)
    threshold = models.IntegerField(default = 1)
    action = models.CharField(max_length = 75, choices = ACTION_CHOICES)
    attribute = models.ForeignKey(Attribute)
    content_type = models.ManyToManyField(ContentType)